package com.darthsith.bolloaudo;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.darthsith.bolloauto.util.ResolveService;

public class MainActivity extends Activity implements OnClickListener {
	
	private Button button;
	private EditText editText;
	
	private ResolveService service;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button=(Button)findViewById(R.id.button1);
        editText=(EditText)findViewById(R.id.editText1);
        button.setOnClickListener(this);
    }
	
	@Override
	public void onClick(View v) {
		if (v.getId()==button.getId()) {
			final ProgressDialog dialog=new ProgressDialog(this);
			dialog.setMessage(getString(R.string.loading));
			dialog.show();
			Runnable r=new Runnable() {
				
				@Override
				public void run() {
					service=new ResolveService(editText.getText().toString());
					Intent intent=new Intent(getApplicationContext(), ResultActivity.class);
					intent.putExtra("data", service.getInfoBollo());
					startActivity(intent);
					dialog.cancel();
				}
			};
			Thread thread=new Thread(r);
			thread.start();
		}
	}
	
}